<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>提交管理·删除提交</title>
    <link rel="stylesheet" type="text/css" href="/static/css/page/delete.css">
</head>
<body>
<div id="popups-window">
    <input type="hidden" name="id">
    <div class="info-box">
        <span class="info">是否确定删除，该操作无法撤销！</span>
    </div>
    <div class="button-box">
        <a class="button confirm" href="#">确定</a>
        <a class="button cancel" href="#">取消</a>
    </div>
</div>

<script type="application/javascript">
    $(function () {
        // 页面元素
        let idEle = $('#popups-window > input[name="id"]');

        // 初始执行操作
        loadId();

        // 获取ID
        function loadId() {
            // 获取前页传来的ID
            let id = window.sessionStorage.getItem('deleteId');

            // 设置到页面
            idEle.val(id);
        }

        // 监听关闭按钮
        $('#popups-window > .button-box > .button.cancel').click(function (e) {
            e.preventDefault();
            $('#popups-window').hide(300, 'swing', function () {
                window.location.reload();
            });
        });

        // 监听确定按钮
        $('#popups-window > .button-box > .button.confirm').click(function () {
            // 获取数据
            let id = idEle.val();

            // 数据提交
            $('#popups-window').html(`<h2 style="margin-left: 20px; margin-right: 20px;">数据提交中...</h2>`);
            $.ajax({
                url: `/api/student-submit/delete/${id}`,
                type: "DELETE",
                success: function (res) {
                    if (res.code === 0) {  // 业务层面成功
                        $.message({
                                type: 'success', content: res.msg, onClose: function () {
                                    window.location.reload();
                                }
                            }
                        );
                    } else {
                        $.message({type: 'error', content: res.msg});
                    }
                }
            });
        });
    });
</script>
</body>
</html>